package com.zhtools.page;


import java.io.Serializable;
import java.util.List;

/**
 * Created by zhanghao on 2017/7/14.
 */
public class PageBean<T> implements Serializable {
    private static final long serialVersionUID = -5941046542137308339L;
    public static final Long MAX_PAGESIZE = Long.valueOf(999999L);
    public static final Long FRIST_PAGE = Long.valueOf(1L);
    public static final Long MYSQL_PAGESTART = Long.valueOf(0L);
    private Long totalRows;
    private List<T> list;
    private Long pageSize;
    private Long page;
    private Long totalPage;
    private Long start;
    private List<OrderBy> orderBy;

    public PageBean() {
    }

    public PageBean(Long totalRows, Long pageSize) {
        this.totalRows = totalRows;
        this.pageSize = pageSize;
    }

    public Long getTotalRows() {
        return this.totalRows;
    }

    public void setTotalRows(Long totalRows) {
        this.totalRows = totalRows;
    }

    public List<T> getList() {
        return this.list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Long getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    public Long getPage() {
        return this.page;
    }

    public void setPage(Long page) {
        this.page = page;
    }

    public Long getTotalPage() {
        if(this.totalRows.longValue() % this.pageSize.longValue() == 0L) {
            this.totalPage = Long.valueOf(this.totalRows.longValue() / this.pageSize.longValue());
        } else {
            this.totalPage = Long.valueOf(this.totalRows.longValue() / this.pageSize.longValue() + 1L);
        }

        return this.totalPage;
    }

    public void setTotalPage(Long totalPage) {
        this.totalPage = totalPage;
    }

    public List<OrderBy> getOrderBy() {
        return this.orderBy;
    }

    public void setOrderBy(List<OrderBy> orderBy) {
        this.orderBy = orderBy;
    }

    public Long getStart() {
        this.start = Long.valueOf((this.page.longValue() - 1L) * this.pageSize.longValue());
        return this.start;
    }

    public void setStart(Long start) {
        this.start = start;
    }

    public boolean hasNextPage() {
        return this.page.longValue() < this.getTotalPage().longValue();
    }

    public PageBean<T> nextPage() {
        this.page = Long.valueOf(this.page.longValue() + 1L);
        return this;
    }
}
